/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.asu.cse360.service.client;

import edu.asu.cse360.dto.ImageDto;
import edu.asu.cse360.service.PhotoService;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;


public class ClientPhotoService implements PhotoService{

    @Override
    public ImageDto save(ImageDto imageDto) {
        try {
            String relaivePath = "testingPhotoService"+Math.random()+".jpg";
            File file = new File(relaivePath);
            ImageIO.write(imageDto.getImage(),"jpg", file);
            return new ImageDto(file.getAbsolutePath(), imageDto.getImage());
        } catch (IOException ex) {
            Logger.getLogger(ClientPhotoService.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

}
